package components.contorls.superClass
{
    import components.core.UIComponent;
    
    import flash.display.MovieClip;
    import flash.events.Event;

    [Event(name="close", type="flash.events.Event")]
    public class BasePanel extends UIComponent
    {
        private var _title:String = "Panel";

        private var _moveMCLeft:Number;

        private var _moveMCRight:Number;

        public function BasePanel()
        {
            super();
        }

        /***************************************
         *
         * 显示对象声明
         *
         * **************************************/

        public function get titleLabel():BaseLabel
        {
            return getChildByName("titleLabelSkin") as BaseLabel;
        }

        public function get closeButton():BaseButton
        {
            return getChildByName("closeButtonSkin") as BaseButton;
        }

        public function get moveMC():MovieClip
        {
            return getChildByName("moveSkin") as MovieClip;
        }

        /***************************************
         *
         * 验证
         *
         * **************************************/

        protected override function commitProperties():void
        {
            super.commitProperties();
            if (!_initialized)
            {
                titleLabel.left = titleLabel.x;
                titleLabel.right = _normalWidth - titleLabel.x - titleLabel.width;

                closeButton.right = _normalWidth - closeButton.x - closeButton.width;
				
				_moveMCLeft=moveMC.x;
				_moveMCRight=_normalWidth-moveMC.x-moveMC.width;
            }
			titleLabel.text = title;
        }

        protected override function measureSizes():Boolean
        {
            if (super.measureSizes())
            {
                moveMC.width = width-_moveMCLeft-_moveMCRight;

                return true;
            }

            return false;
        }


        protected override function updateDisplayList():void
        {
            super.updateDisplayList();
        }

        /***************************************
         *
         * 组件定义
         ***************************************/

        [Inspectable(defaultValue="Panel")]
        public function get title():String
        {
            return _title;
        }

        public function set title(str:String):void
        {
            _title = str;
           	invalidate();
        }

        /***************************************
         *
         * 其他代码
         *
         * **************************************/

        public override function set focusComp(value:UIComponent):void
        {
            super.focusComp = value;

            titleLabel.focusComp = focusComp;
            closeButton.focusComp = focusComp;
        }

        public override function destroy():void
        {
            super.destroy();
        }

        public override function validateNow():void
        {
            super.validateNow();
            titleLabel.validateNow();
        }
    }
}